package documenteditor;

import java_cup.runtime.Symbol;
import java.io.*;
%%
%{
	FileWriter     DC_fWriter;
	PrintWriter    DC_Salida;
	String			strCad;

  public void imprime_error(String str) throws IOException{
	try{
		strCad = "Error lexico con caracter '"+ str + "' en la columna "+(yychar+1)+" y fila "+(yyline+1) + " ha sido omitido";
		DC_fWriter = new FileWriter("c:\\Errores.txt",true);
		DC_Salida = new PrintWriter(DC_fWriter);
		DC_Salida.println(strCad);
		DC_fWriter.close();
    	System.out.println(strCad);
        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
  }
%}
%init{
	try{
		FileWriter     DC_fWriter;
		PrintWriter    DC_Salida;
		String			strCad;
		DC_fWriter = new FileWriter("c:\\Errores.txt",false);
		DC_Salida = new PrintWriter(DC_fWriter);
		DC_Salida.println("/******* ERRORES ARCHIVO PERSONAJE *******/");
		DC_Salida.println("");
		DC_fWriter.close();
        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
%init}
%public
%class lexico
%cup
%full
%line
%char
%ignorecase
%eofval{
	return (new Symbol(Simbol.EOF));
%eofval} 
letra = [A-Za-z]
%%

"reporte" { return new Symbol(Simbol.REPORTE, new token(yytext(), (yychar+1), (yyline+1))); }
"titulo" { return new Symbol(Simbol.TITULO, new token(yytext(), (yychar+1), (yyline+1))); }
"origenes" { return new Symbol(Simbol.ORIGENES, new token(yytext(), (yychar+1), (yyline+1))); }
"estilos" { return new Symbol(Simbol.ESTILOS, new token(yytext(), (yychar+1), (yyline+1))); }
"estilo" { return new Symbol(Simbol.ESTILO, new token(yytext(), (yychar+1), (yyline+1))); }

"basedatos" { return new Symbol(Simbol.BD, new token(yytext(), (yychar+1), (yyline+1))); }
"nombre" { return new Symbol(Simbol.NOMBRE, new token(yytext(), (yychar+1), (yyline+1))); }
"tabla" { return new Symbol(Simbol.TABLA, new token(yytext(), (yychar+1), (yyline+1))); }
"campo" { return new Symbol(Simbol.CAMPO, new token(yytext(), (yychar+1), (yyline+1))); }
"tipo" { return new Symbol(Simbol.TIPO, new token(yytext(), (yychar+1), (yyline+1))); }
"\"varchar\"" { return new Symbol(Simbol.VAR_CHAR, new token(yytext(), (yychar+1), (yyline+1))); }
"\"int\"" { return new Symbol(Simbol.ENTERO, new token(yytext(), (yychar+1), (yyline+1))); }
"\"float\"" { return new Symbol(Simbol.FLOTANTE, new token(yytext(), (yychar+1), (yyline+1))); }
"\"datetime\"" { return new Symbol(Simbol.FECHA, new token(yytext(), (yychar+1), (yyline+1))); }
"\"tinyint\"" { return new Symbol(Simbol.TINY_INT, new token(yytext(), (yychar+1), (yyline+1))); }

"dataset" { return new Symbol(Simbol.DATASET, new token(yytext(), (yychar+1), (yyline+1))); }
"campos" { return new Symbol(Simbol.CAMPOS, new token(yytext(), (yychar+1), (yyline+1))); }
"consulta" { return new Symbol(Simbol.CONSULTA, new token(yytext(), (yychar+1), (yyline+1))); }
"![CDATA[" { return new Symbol(Simbol.CDATAINI, new token(yytext(), (yychar+1), (yyline+1))); }
"]]" { return new Symbol(Simbol.CDATAFIN, new token(yytext(), (yychar+1), (yyline+1))); }
"parametro" { return new Symbol(Simbol.PARAMETRO, new token(yytext(), (yychar+1), (yyline+1))); }
"formula" { return new Symbol(Simbol.FORMULA, new token(yytext(), (yychar+1), (yyline+1))); }
"return" { return new Symbol(Simbol.RETORNO, new token(yytext(), (yychar+1), (yyline+1))); }
"#"([A-F]|[0-9])+ { return new Symbol(Simbol.HEXA, new token(yytext(), (yychar+1), (yyline+1))); }

"OR" { return new Symbol(Simbol.OR, new token(yytext(), (yychar+1), (yyline+1))); }
"AND" { return new Symbol(Simbol.AND, new token(yytext(), (yychar+1), (yyline+1))); }
"=" { return new Symbol(Simbol.IGUAL, new token(yytext(), (yychar+1), (yyline+1))); }
"<>" { return new Symbol(Simbol.DIFERENTE, new token(yytext(), (yychar+1), (yyline+1))); }
"<" { return new Symbol(Simbol.MENOR, new token(yytext(), (yychar+1), (yyline+1))); }
">" { return new Symbol(Simbol.MAYOR, new token(yytext(), (yychar+1), (yyline+1))); }
"<=" { return new Symbol(Simbol.MENOR_IGUAL, new token(yytext(), (yychar+1), (yyline+1))); }
">=" { return new Symbol(Simbol.MAYOR_IGUAL, new token(yytext(), (yychar+1), (yyline+1))); }
"+" { return new Symbol(Simbol.MAS, new token(yytext(), (yychar+1), (yyline+1))); }
"-" { return new Symbol(Simbol.MENOS, new token(yytext(), (yychar+1), (yyline+1))); }
"*" { return new Symbol(Simbol.POR, new token(yytext(), (yychar+1), (yyline+1))); }
"/" { return new Symbol(Simbol.DIV, new token(yytext(), (yychar+1), (yyline+1))); }
"mod" { return new Symbol(Simbol.MOD, new token(yytext(), (yychar+1), (yyline+1))); }
"\"" { return new Symbol(Simbol.DCOMILLA, new token(yytext(), (yychar+1), (yyline+1))); }
"&" { return new Symbol(Simbol.AMPER, new token(yytext(), (yychar+1), (yyline+1))); }
"$" { return new Symbol(Simbol.DOLAR, new token(yytext(), (yychar+1), (yyline+1))); }
"@" { return new Symbol(Simbol.ARROBA, new token(yytext(), (yychar+1), (yyline+1))); }
"#" { return new Symbol(Simbol.SHEL, new token(yytext(), (yychar+1), (yyline+1))); }
"(" { return new Symbol(Simbol.PARA, new token(yytext(), (yychar+1), (yyline+1))); }
")" { return new Symbol(Simbol.PARC, new token(yytext(), (yychar+1), (yyline+1))); }
"{" { return new Symbol(Simbol.LLAVEA, new token(yytext(), (yychar+1), (yyline+1))); }
"}" { return new Symbol(Simbol.LLAVEC, new token(yytext(), (yychar+1), (yyline+1))); }
"," { return new Symbol(Simbol.COMA, new token(yytext(), (yychar+1), (yyline+1))); }
"." { return new Symbol(Simbol.PUNTO, new token(yytext(), (yychar+1), (yyline+1))); }
":" { return new Symbol(Simbol.DOSP, new token(yytext(), (yychar+1), (yyline+1))); }
";" { return new Symbol(Simbol.PCOMA, new token(yytext(), (yychar+1), (yyline+1))); }

"IF" { return new Symbol(Simbol.SI, new token(yytext(), (yychar+1), (yyline+1))); }
"ELSEIF" { return new Symbol(Simbol.SINOSI, new token(yytext(), (yychar+1), (yyline+1))); }
"ELSE" { return new Symbol(Simbol.SINO, new token(yytext(), (yychar+1), (yyline+1))); }
"THEN" { return new Symbol(Simbol.ENTONCES, new token(yytext(), (yychar+1), (yyline+1))); }
"END" { return new Symbol(Simbol.FIN, new token(yytext(), (yychar+1), (yyline+1))); }
"SELECT" { return new Symbol(Simbol.SELECCION, new token(yytext(), (yychar+1), (yyline+1))); }
"CASE" { return new Symbol(Simbol.CASO, new token(yytext(), (yychar+1), (yyline+1))); }
"DEFAULT" { return new Symbol(Simbol.PREDET, new token(yytext(), (yychar+1), (yyline+1))); }

"RAIZ" { return new Symbol(Simbol.RAIZ, new token(yytext(), (yychar+1), (yyline+1))); }
"POTENCIA" { return new Symbol(Simbol.POTENCIA, new token(yytext(), (yychar+1), (yyline+1))); }
"SUM" { return new Symbol(Simbol.SUMA, new token(yytext(), (yychar+1), (yyline+1))); }
"COUNT" { return new Symbol(Simbol.CONTEO, new token(yytext(), (yychar+1), (yyline+1))); }
"MAX" { return new Symbol(Simbol.MAXIMO, new token(yytext(), (yychar+1), (yyline+1))); }
"MIN" { return new Symbol(Simbol.MINIMO, new token(yytext(), (yychar+1), (yyline+1))); }
"TODOUBLE" { return new Symbol(Simbol.ADOBLE, new token(yytext(), (yychar+1), (yyline+1))); }
"TOINT" { return new Symbol(Simbol.AENTERO, new token(yytext(), (yychar+1), (yyline+1))); }
"TOFLOAT" { return new Symbol(Simbol.AFLOTANTE, new token(yytext(), (yychar+1), (yyline+1))); }
"SUBSTRING" { return new Symbol(Simbol.SUBCAD, new token(yytext(), (yychar+1), (yyline+1))); }
"CONCAT" { return new Symbol(Simbol.CONCATENA, new token(yytext(), (yychar+1), (yyline+1))); }
"TOSTRING" { return new Symbol(Simbol.ACADENA, new token(yytext(), (yychar+1), (yyline+1))); }
"DAY" { return new Symbol(Simbol.DIA, new token(yytext(), (yychar+1), (yyline+1))); }
"MONTH" { return new Symbol(Simbol.MES, new token(yytext(), (yychar+1), (yyline+1))); }
"YEAR" { return new Symbol(Simbol.ANIO, new token(yytext(), (yychar+1), (yyline+1))); }

"COLOR" { return new Symbol(Simbol.COLOR, new token(yytext(), (yychar+1), (yyline+1))); }
"ANCHO" { return new Symbol(Simbol.ANCHO, new token(yytext(), (yychar+1), (yyline+1))); }
"ALTO" { return new Symbol(Simbol.ALTO, new token(yytext(), (yychar+1), (yyline+1))); }
"FUENTE" { return new Symbol(Simbol.FUENTE, new token(yytext(), (yychar+1), (yyline+1))); }
"POSICIONX" { return new Symbol(Simbol.POSICIONX, new token(yytext(), (yychar+1), (yyline+1))); }
"POSICIONY" { return new Symbol(Simbol.POSICIONY, new token(yytext(), (yychar+1), (yyline+1))); }

"ENCABEZADOS" { return new Symbol(Simbol.ENCABEZADOS, new token(yytext(), (yychar+1), (yyline+1))); }
"ENCABEZADO" { return new Symbol(Simbol.ENCABEZADO, new token(yytext(), (yychar+1), (yyline+1))); }
"numfilas" { return new Symbol(Simbol.FILAS, new token(yytext(), (yychar+1), (yyline+1))); }
"ORDEN" { return new Symbol(Simbol.ORDEN, new token(yytext(), (yychar+1), (yyline+1))); }
"PIE" { return new Symbol(Simbol.PIE, new token(yytext(), (yychar+1), (yyline+1))); }
"CUERPO" { return new Symbol(Simbol.CUERPO, new token(yytext(), (yychar+1), (yyline+1))); }
"ESTILOPARES" { return new Symbol(Simbol.PAR, new token(yytext(), (yychar+1), (yyline+1))); }
"ESTILOIMPARES" { return new Symbol(Simbol.IMPAR, new token(yytext(), (yychar+1), (yyline+1))); }
"VALOR" { return new Symbol(Simbol.VALOR, new token(yytext(), (yychar+1), (yyline+1))); }
"SUB" { return new Symbol(Simbol.SUB, new token(yytext(), (yychar+1), (yyline+1))); }
"ETIQUETA" { return new Symbol(Simbol.ETIQUETA, new token(yytext(), (yychar+1), (yyline+1))); }

"PARAM" { return new Symbol(Simbol.PARAM, new token(yytext(), (yychar+1), (yyline+1))); }
"MUESTRATOTAL" { return new Symbol(Simbol.TOTAL, new token(yytext(), (yychar+1), (yyline+1))); }

("\"true\""|"\"false\"") { return new Symbol(Simbol.BOOL, new token(yytext(), (yychar+1), (yyline+1))); }

('){letra}(') {  return new Symbol(Simbol.CARACTER, new token(yytext(), (yychar+1), (yyline+1))); }
({letra})({letra}|[0-9]|[_])* { return new Symbol(Simbol.ID, new token(yytext(), (yychar+1), (yyline+1))); }
[0-9]+"."?[0-9]* { return new Symbol(Simbol.NUM, new token(yytext(), (yychar+1), (yyline+1))); }
"\""([^"\""^"$"])*"\"" {  return new Symbol(Simbol.CAD, new token(yytext(), (yychar+1), (yyline+1))); }

[\n] {yychar = 0;}
[ \t\r\f] { /* ignore white space. */ }
. { imprime_error(yytext()); ;}